﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;

namespace University.Workshop.WinApp
{
    public partial class ViewNoteBook : Form
    {
        public ViewNoteBook()
        {
            InitializeComponent();
            LoadNoteBooks();
        }

        private void LoadNoteBooks()
        {
            DataTable dataNoteBook = AgendaManager.LoadAgenda();
            for (int i = 0; i < dataNoteBook.Rows.Count; i++) 
            {
                listBoxNoteBooks.Items.Add(dataNoteBook.Rows[i]["NameNoteBook"].ToString());
            }
        }

        private void buttonNewNoteBook_Click(object sender, EventArgs e)
        {
            CreateNoteBook newNoteBook = new CreateNoteBook();
            newNoteBook.ShowDialog();
            listBoxNoteBooks.Items.Clear();
            LoadNoteBooks();
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonEditNoteBook_Click(object sender, EventArgs e)
        {
            string itemSelected; 
            if (listBoxNoteBooks.SelectedIndex >= 0)
            {
                itemSelected = listBoxNoteBooks.SelectedItem.ToString();
                CreateNoteBook newNoteBook = new CreateNoteBook(itemSelected);
                newNoteBook.ShowDialog();
                listBoxNoteBooks.Items.Clear();
                LoadNoteBooks();
            }
            else
            {
                MessageBox.Show("Error");
            }
        }

        private void ViewNoteBook_FormClosed(object sender, FormClosedEventArgs e)
        {
            Singleton.Instance.valid = true;
        }
    }
}
